﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Shakes_and_Fidget___Charplaner
{
    public partial class settings : Form
    {
        RegistryKey lm = Registry.LocalMachine;
        sfc main = (sfc)sfc.ActiveForm;
        public settings()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            path.ShowDialog();
        }
        private void settings_MouseMove(object sender, MouseEventArgs e)
        {
            textBox1.Text = path.SelectedPath;
        }
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            op_percent.Text = trackBar1.Value.ToString() + "%";
            main.Opacity = (double)trackBar1.Value/100.00;
        }
        private void cb_opacity_CheckedChanged(object sender, EventArgs e)
        {
            if (cb_opacity.Checked)
            {
                main.Opacity = (double)trackBar1.Value / 100.00;
                trackBar1.Enabled = true;
            }
            if (!cb_opacity.Checked)
            {
                main.Opacity = 1;
                trackBar1.Enabled = false;
            }
        }
        private void close_Click(object sender, EventArgs e)
        {
            if ((string)lm.OpenSubKey("Software", true).OpenSubKey("SFC", true).OpenSubKey("Settings", true).GetValue("TopMost") == "True")
                cb_top.Checked = true;
            else
                cb_top.Checked = false;
            int i = (int)lm.OpenSubKey("Software", true).OpenSubKey("SFC", true).OpenSubKey("Settings", true).GetValue("Opacity");
            main.Opacity = i/100.00;
            if (i != 100)
                cb_opacity.Checked = true;
            this.Close();
        }
        private void cb_top_CheckedChanged(object sender, EventArgs e)
        {
            if (cb_top.Checked)
                main.TopMost = true;
            if (!cb_top.Checked)
                main.TopMost = false;
            this.TopMost = true;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            main.d_load.InitialDirectory = path.SelectedPath;
            main.d_save.InitialDirectory = path.SelectedPath;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            button2_Click(sender, e);
            lm.OpenSubKey("Software", true).OpenSubKey("SFC", true).CreateSubKey("Settings").SetValue("Opacity", trackBar1.Value);
            lm.OpenSubKey("Software", true).OpenSubKey("SFC", true).OpenSubKey("Settings", true).SetValue("TopMost", cb_top.Checked);
            if(textBox1.Text != "")
                lm.OpenSubKey("Software", true).OpenSubKey("SFC", true).OpenSubKey("Settings", true).SetValue("Path", textBox1.Text);
            this.Close();
        }
        private void settings_Load(object sender, EventArgs e)
        {
            if ((string)lm.OpenSubKey("Software", true).OpenSubKey("SFC", true).OpenSubKey("Settings", true).GetValue("TopMost") == "True")
                cb_top.Checked = true;
            else
                cb_top.Checked = false;
            int i = (int)lm.OpenSubKey("Software", true).OpenSubKey("SFC", true).OpenSubKey("Settings", true).GetValue("Opacity");
            trackBar1.Value = i;
            if (i != 100)
                cb_opacity.Checked = true;
            trackBar1_Scroll(sender, e);
        }
    }
}
